type RequestOptions = {
  method?: string;
  data?: Record<string, string>;
  query?: Record<string, string>;
};

export default function request(url: string, options: RequestOptions) {
  const { method, data, query } = options;
  let queryString = "";
  if (query) {
    queryString = "?" + new URLSearchParams(query).toString();
  }
  return fetch(url + queryString, {
    method,
    body: data && JSON.stringify(data),
  });
}
